package com.hoshiicloud.withdraw.controller.common;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hoshiicloud.common.controller.BaseController;
import com.hoshiicloud.withdraw.entity.UrlInfo;
import com.hoshiicloud.withdraw.service.UrlInfoService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * (UrlInfo)表控制层
 *
 * @author makejava
 * @since 2019-08-23 15:07:40
 */
@RestController
@Slf4j
public class UrlInfoController extends BaseController {
	/**
	 * 服务对象
	 */
	@Autowired
	private UrlInfoService urlInfoService;

	@ApiOperation(value = "查询提现用户签约记录")
	@RequestMapping("/{url}")
	public void contractRecord(@PathVariable("url") String shortUrl, HttpServletResponse response) throws IOException {
		QueryWrapper<UrlInfo> urlInfoQueryWrapper = new QueryWrapper<>();
		urlInfoQueryWrapper.lambda().eq(UrlInfo::getShortUrl, shortUrl);
		// 设置响应内容类型
		response.setContentType("text/html;charset=UTF-8");
		// 要重定向的新位置
		String site = urlInfoService.getOne(urlInfoQueryWrapper).getLongUrl();
		response.setStatus(response.SC_MOVED_TEMPORARILY);
		response.setHeader("Location", site);
	}
}